package com.ybl.store.backend.controller.store;

import com.ybl.store.backend.dto.req.store.LogProductNumberSaveReqDTO;
import com.ybl.store.backend.dto.req.store.LogProductNumberUpdateReqDTO;
import com.ybl.store.backend.dto.resp.store.LogProductNumberPageRespDTO;
import com.ybl.store.backend.service.store.LogProductNumberService;
import com.ybl.store.common.convention.result.Result;
import com.ybl.store.common.convention.result.Results;
import com.ybl.store.common.entity.ListRespDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/backend/log/product-number")
public class LogProductNumberController {

    private final LogProductNumberService logProductNumberService;

    @PostMapping
    public Result<Void> saveLogProductNumber(@RequestBody LogProductNumberSaveReqDTO requestParam) {
        logProductNumberService.saveLogProductNumber(requestParam);
        return Results.success();
    }

    @DeleteMapping
    public Result<Void> deleteLogProductNumberById(@RequestParam Long id) {
        logProductNumberService.deleteLogProductNumberById(id);
        return Results.success();
    }

    @PutMapping
    public Result<Void> updateLogProductNumber(@RequestBody LogProductNumberUpdateReqDTO requestParam) {
        logProductNumberService.updateLogProductNumber(requestParam);
        return Results.success();
    }

    @GetMapping("/page")
    public Result<ListRespDTO<LogProductNumberPageRespDTO>> pageLogProductNumber(
            @RequestParam("pn") Integer pn,
            @RequestParam("ps") Integer ps,
            @RequestParam(required = false) Long productId)
    {
        return Results.success(logProductNumberService.pageLogProductNumber(pn, ps, productId));
    }
}
